package com.itheima.redis;

import redis.clients.jedis.Jedis;
import sun.management.Agent;

public class TestSpring {

    private static String phone;

    public static void main(String[] args) throws InterruptedException {
        //创建 jedis对象
        Jedis jedis = new Jedis("192.168.72.102", 6379);

        //测试是否连通
        String ping = jedis.ping();
        System.out.println(ping);
        //测试存值和获取值
        jedis.set("phone", "1362211");
        String name = jedis.get("name");
        String phone = jedis.get("phone");
        System.out.println("name:" + name + "phone:" + phone);
        //删除值
        jedis.del("name");
        //为元素进行+1操作
        jedis.incr("age");

        System.out.println(jedis.get("age"));
        //为元素进行+n操作
        jedis.incrBy("age", 5);
        System.out.println(jedis.get("age"));
        //拼接字符串
        jedis.append("phone", "1591");
        System.out.println(jedis.get("phone"));
        //为已有的key设置时长
        jedis.expire("age", 10);
        int i = 10;
        while (jedis.exists("age")) {

            System.out.println(--i);
            Thread.sleep(1000);
        }
        System.out.println("age:"+jedis.exists("age"));
        //为新建的key设置有效时间
        jedis.setex("wife", 10, "paner");
        int y = 10;
        while (jedis.exists("wife")) {

            System.out.println(--y);
            Thread.sleep(1000);
        }
        System.out.println( "wife:" + jedis.exists("wife"));
        jedis.close();


    }


}
